package components.plugins.effects
{
	import UIFree.uif_app;
	
	import UIUtils.uif_util;
	
	import flash.display.BitmapData;
	import flash.display.BlendMode;
	import flash.events.EventDispatcher;
	import flash.geom.Point;

	public class clt_baseEffect extends EventDispatcher {
		protected static const blendModes: Array = [BlendMode.NORMAL, BlendMode.ADD, BlendMode.ALPHA, BlendMode.DARKEN, BlendMode.DIFFERENCE, 
			BlendMode.ERASE, BlendMode.HARDLIGHT, BlendMode.INVERT, BlendMode.LAYER, BlendMode.LIGHTEN, BlendMode.MULTIPLY, 
			BlendMode.OVERLAY, BlendMode.SCREEN, BlendMode.SHADER, BlendMode.SUBTRACT]
		private var _params: Object;
		public function clt_baseEffect(a_params: Object) {
			_params = uif_util.unionObj({
				blendModeIndex: 0
			}, a_params);
		}
		
		public function get params(): Object {
			return _params;
		}
		
		protected function get locale(): Object {
			return (uif_app.instance() as clt_clothingBase).locale;
		}
		
		public function execute(bitmapData: BitmapData): void {
			
		}
		
		protected function changeValue(a_value: Number, add_inc: Number, a_limit: Number): Number {
			if (a_value + add_inc > a_limit)
				return (a_value + add_inc) - a_limit;
			return a_value += add_inc;
		}
		
		public function incValue1(): void {
			
		}
		
		public function incValue2(): void {
			
		}
		
		public function incValue3(): void {
			
		}
		
		public function incValue4(): void {
			params.blendModeIndex = changeValue(params.blendModeIndex, 1, blendModes.length);
		}
		
		protected function get blendMode(): String {
			return blendModes[params.blendModeIndex];
		}
		
		protected function get blendMode100(): Number {
			return params.blendModeIndex/blendModes.length * 100;
		}
		
		public static function copyBD(bitmapData: BitmapData, trans: Boolean= false, backColor:uint=0xFFFFFF): BitmapData {
			var a_tmp: BitmapData = new BitmapData(bitmapData.width, bitmapData.height, trans, backColor);
			a_tmp.copyPixels(bitmapData, bitmapData.rect, new Point());
			return a_tmp;
		}
		
		public function get paramName(): Array {
			return getParamName();
		}
		
		protected function getParamName(): Array {
			return ['','','',''];
		}
		
		public function get values(): Array {
			return getValues();
		}
		
		public function set values(a_set: Array): void {
			setValues(a_set);
		}
		
		protected function getValues(): Array {
			return [0,0,0, blendMode100];
		}
		
		protected function setValues(a_set: Array): void {
			params.blendModeIndex = Math.ceil(a_set[3]/100 * blendModes.length);
		}
	}
}